package com.example.scaffolding.ui.user

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.scaffolding.R
import com.example.scaffolding.db.bean.User
import com.example.scaffolding.ui.user.RecyclerAdapterCommon.RecyclerViewHolder
import java.util.*

class RecyclerAdapterCommon : RecyclerView.Adapter<RecyclerViewHolder>() {
    private val mUsers: MutableList<User> = ArrayList()
    fun setmUsers(mUsers: List<User>) {
        this.mUsers.clear()
        this.mUsers.addAll(mUsers)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item, parent, false)
        return RecyclerViewHolder(view)
    }

    override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {
        val concert = mUsers[position]
        if (concert != null) {
            holder.user_id.text = "id=" + concert.id + "----"
            holder.user_name.text = "姓名=" + concert.name
            holder.user_type.text = "----type=" + concert.type + ""
        }
    }

    override fun getItemCount(): Int {
        return mUsers.size
    }

    class RecyclerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var user_id: TextView
        var user_name: TextView
        var user_type: TextView

        init {
            user_id = itemView.findViewById(R.id.user_id)
            user_name = itemView.findViewById(R.id.user_name)
            user_type = itemView.findViewById(R.id.user_type)
        }
    }
}